home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech's Sprocket™ / SprocketGX / AppSpecific / App.cp next >
Encoding:
Text File  |  1994-10-18  |  5.9 KB  |  307 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        App.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Windows.h>
  15. #include <Dialogs.h>
  16. #include <Menus.h>
  17. #include <Desk.h>
  18. #include <Errors.h>
  19. #include <Resources.h>
  20. #include <StandardFile.h>
  21. #include <Devices.h>        //    was <Desk.h>
  22.  
  23. #include "AppLib.h"
  24. #include "Window.h"
  25. #include "StandardMenus.h"
  26. #include "SplashWindow.h"
  27.  
  28. #include "GXToolWindow.h"
  29. #include "GXDocWindow.h"
  30. #include "PreferencesDialogWindow.h"
  31. #include "MailableDocWindow.h"
  32.  
  33. #include "Preferences.h"
  34.  
  35. AppPreferences    gPreferences;
  36.  
  37. //    Function Prototypes:
  38.  
  39. void    AboutBox(void);
  40. void    OpenExistingDocument(void);
  41.  
  42.  
  43. #define    kAboutBoxFor68K                256
  44. #define    kAboutBoxForPowerPC            257
  45. #define        iCreditsButton                2
  46.  
  47. #define    kCreditsBox                    258
  48.  
  49.  
  50. #if    qUseQuickDrawGX
  51. // gAppPrintingOverrideUPP is a universal proc pointer for our printing event
  52. // override.  This is so that our override can be native PowerPC code if necessary.
  53.  
  54. GXPrintingEventUPP    gAppPrintingOverrideUPP;
  55.  
  56. //    PrintingEventOverride is our generic event handler for QuickDrawGX.
  57. //    It alows us to handle events while the QuickDrawGX movable modal
  58. //    printing dialogs are displayed.
  59. static OSErr AppPrintingEventOverride(EventRecord *pEvent, Boolean theFilterEvent)
  60. {
  61.     CSavePort  aSavePort(nil);
  62.     
  63.     if (theFilterEvent == false)
  64.         switch (pEvent->what)
  65.         {
  66.             case mouseDown:
  67.             case keyDown:
  68.             case autoKey:
  69.                 break;
  70.  
  71.             default:
  72.                 HandleEvent(pEvent);
  73.         }
  74.     return noErr;
  75. }
  76. #endif
  77.  
  78.  
  79. OSErr SetupApplication(void)
  80. {
  81. #if    qUseQuickDrawGX
  82.     if (gHasQuickDrawGX)
  83.         gAppPrintingOverrideUPP = NewGXPrintingEventProc(AppPrintingEventOverride);
  84. #endif
  85.  
  86.     if (gHasAOCE)
  87.     {
  88.         MenuHandle    hMenu = GetMenu(mDebug);
  89.         if (hMenu)
  90.             InsertMenu(hMenu, 0);
  91.         EnableMenuItem(mDebug, iNewMailableWindow, true);
  92.     }
  93.     
  94.     TGXToolWindow    * someTools = new TGXToolWindow();
  95.  
  96.     gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
  97.  
  98.     InitCursor();
  99.     return (noErr);
  100. }
  101.  
  102. void TearDownApplication(void)
  103. {
  104.     DisposeRoutineDescriptor(gAppPrintingOverrideUPP);
  105. //    Not much to do yet.
  106. }
  107.     
  108. void HandleMenu(TWindow * topWindowObj, long menuCode)
  109. {
  110.     short    menu = (short) (menuCode >> 16);
  111.     short    item = (short) (menuCode & 0xffff);
  112.     Str255    deskAccName;
  113.     
  114.     switch (menu)
  115.     {
  116.         case    mApple:
  117.             switch (item)
  118.             {
  119.                 case    iAbout:
  120.                     AboutBox();
  121.                     break;
  122.                     
  123.                 default:
  124.                     GetItem(GetMHandle(mApple),item,deskAccName);
  125.                     (void) OpenDeskAcc(deskAccName);
  126.                     break;
  127.             }
  128.             break;
  129.             
  130.         case    mFile:
  131.             switch (item)
  132.             {
  133.                 case    iNew:
  134.                     OpenNewDocument();
  135.                     break;
  136.                 
  137.                 case    iOpen:
  138.                     OpenExistingDocument();
  139.                     break;
  140.                 
  141.                 case    iClose:
  142.                     HandleClose(FrontNonFloatingWindow());
  143.                     break;
  144.                     
  145.                 case    iPageSetup:
  146.                 case    iCustomPageSetup:
  147.                 case    iPrint:
  148.                 case    iPrintOneCopy:
  149.                     WindowCommand(FrontNonFloatingWindow(), menu, item);
  150.                     break;
  151.                     
  152.                 case    iPreferences:
  153.                     TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
  154.                     break;
  155.  
  156.                 case    iQuit:
  157.                     gDone = QuitApplication();
  158.                     break;
  159.                     
  160.                 default:
  161.                     WindowCommand(FrontNonFloatingWindow(), menu, item);
  162.                     break;
  163.             }
  164.             break;
  165.         
  166.         case    mEdit:
  167.             switch (item)
  168.             {
  169.                 case    iUndo :
  170.                 case    iCut :
  171.                 case    iCopy :
  172.                 case    iPaste :
  173.                 case    iSelectAll :
  174.                     if (SystemEdit(item-1) == false)
  175.                         if (topWindowObj)
  176.                             topWindowObj->DoEditMenu(item);
  177.                     break;
  178.                 case    iNextPage:
  179.                 case    iPreviousPage:
  180.                 case    iGotoPage:
  181.                     WindowCommand(FrontNonFloatingWindow(), menu, item);
  182.                     break;
  183.                 case    iShowOrHideClipboard:
  184.                     break;
  185.             }
  186.         
  187.         case    mDebug:
  188.             switch(item)
  189.             {
  190.                 case    iNewMailableWindow:
  191.                     TMailableDocWindow *aWackyThing = new TMailableDocWindow;
  192.                     break;
  193.                     
  194.                 default:
  195.                     break;
  196.             }
  197.             break;
  198.  
  199.         default:
  200.             break;
  201.     }
  202.     HiliteMenu(0);
  203. }
  204.  
  205. void AboutBox(void)
  206. {
  207.     Handle            versionHandle;
  208.     StringPtr        nullStr = (StringPtr) "\p";
  209.     StringPtr        shortVersionString = nullStr;
  210.     short            itemHit;
  211.     
  212.     versionHandle = GetResource('vers',1);
  213.     if (versionHandle)
  214.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  215.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  216.     ReleaseResource(versionHandle);
  217.  
  218. #ifndef    powerc
  219.     itemHit = StandardAlert(kAboutBoxFor68K);
  220. #else
  221.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  222. #endif
  223.  
  224.     if (itemHit == iCreditsButton)
  225.         StandardAlert(kCreditsBox);
  226. }
  227.  
  228.  
  229. void OpenExistingDocument(void)
  230. {
  231.     StandardFileReply    aSfReply;
  232.     SFTypeList            ourTypes;
  233.     Point    where = { -1, -1 };
  234.     
  235.     ourTypes[0] = 'sjob';
  236.     
  237.     HiliteWindowsForModalDialog(false);
  238.     CustomGetFile((FileFilterYDUPP) nil, 1, ourTypes, &aSfReply, 0, where,
  239.                   (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
  240.     HiliteWindowsForModalDialog(true);
  241.     if (aSfReply.sfGood)
  242.     {
  243.         LetterDescriptor        aLetterDescriptor;
  244.         
  245.         aLetterDescriptor.onDisk = true;
  246.         aLetterDescriptor.u.fileSpec = aSfReply.sfFile;
  247.         (void)OpenDocument(&aLetterDescriptor, nil);
  248.     }
  249. }
  250.  
  251. void ConvertClipboard(void)
  252. {
  253. }
  254.  
  255. OSErr OpenNewDocument(void)
  256. {
  257.     TGXDocWindow    *pNewWindow = new TGXDocWindow();
  258.     if (pNewWindow)
  259.     {
  260.         pNewWindow->CreateSampleImage();
  261.         return noErr;
  262.     }
  263.     return memFullErr;
  264. }
  265.  
  266. /****
  267. struct LetterDescriptor {
  268.     Boolean                        onDisk;
  269.     union {
  270.         FSSpec                        fileSpec;
  271.         LetterSpec                    mailboxSpec;
  272.     }                            u;
  273. struct LetterSpec {
  274.     unsigned long                spec[3];
  275. };
  276. };
  277. ****/
  278. OSErr OpenDocument(LetterDescriptor* pDocument, void * /*unused*/)
  279. {
  280.     TGXDocWindow    *pNewWindow = new TGXDocWindow();
  281.     if (pNewWindow)
  282.     {
  283.         pNewWindow->SetDocFile(&pDocument->u.fileSpec);
  284.         pNewWindow->ReadPage(1);
  285.         return noErr;
  286.     }
  287.     return memFullErr;
  288. }
  289.  
  290. OSErr PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  291. {
  292.     return noErr;
  293. }
  294.  
  295. Boolean QuitApplication(void)
  296. {
  297.     WindowPtr pFrontNonFloater;
  298.  
  299.     while ((pFrontNonFloater = FrontNonFloatingWindow()), pFrontNonFloater)
  300.     {
  301.         HandleClose(pFrontNonFloater);
  302.         if (pFrontNonFloater == FrontNonFloatingWindow())    // failed
  303.             return false;
  304.     }
  305.     return true;
  306. }
  307.